﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ProgNetComponentsDx.Cache
{
    public class CacheItem<TValue> : ICacheItem
    {
        private long _TimesUsed;
        public TValue Value { get; set; }
        public long TimesUsed { get { return _TimesUsed; } }
        public void IncrementUsage()
        {
            Interlocked.Increment(ref _TimesUsed);
        }
        public void DecrementUsage()
        {
            Interlocked.Decrement(ref _TimesUsed);
        }
        public bool IsUsed
        {
            get { return TimesUsed > 0; }
        }

        object ICacheItem.Value
        {
            get
            {
                return this.Value;
            }
            set
            {
                this.Value = (TValue)value;
            }
        }
    }
}
